package com.hns.can.mainte.service;

import java.io.File;
import java.io.OutputStream;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.FileUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hns.can.common.aop.orgTree.LeftOrgAnnotation;
import com.hns.frame.service.CommonService;

/**
 * @author:zhangzq
 * @email:
 * @version Revision 2.0.0
 */
@Service
public class CommonExportService extends CommonService{

//	@Autowired
//    private SysAuthorityFuncService sysAuthorityFuncService;
	
	public void exportExcel(String template, List list, String name)
			throws Exception {

	}

	public void exportPdf(String[] tableHeaderName, String[] tablePropertyName,
			List list, String name) throws Exception {

	}

	@LeftOrgAnnotation()
	@Transactional
	public List<String> getCarIdByDrvIds(List<String> orgIds) {
		return sqlMapDao.selectList("realTimeFailure.getCarIdByDrvIds");
	}
	
	public static void downloadFile(String filePath, HttpServletResponse response){
    	File temp = new File(filePath);
        try {
        	OutputStream os = response.getOutputStream();
            response.reset();
            response.setHeader("Content-Disposition", "attachment; filename=" + new String(temp.getName().getBytes("gbk"), "ISO8859-1"));
            response.setContentType("application/octet-stream; charset=utf-8");
            os.write(FileUtils.readFileToByteArray(temp));
            os.flush();
        } catch (Exception e){
        	e.printStackTrace();
        }
    }
 }
